package top.i51213.fastlink;

import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

public class Util {

    public static String getUriDisplayName(Context context, Uri uri) {
        String[] filePathColumn = {MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME};
        ContentResolver contentResolver = context.getContentResolver();
        Cursor cursor = contentResolver.query(uri, filePathColumn, null, null, null);
        String disPlayName="";
        if (cursor != null) {
            cursor.moveToFirst();
            int index = cursor.getColumnIndex(filePathColumn[1]);
            //这里有可能为空 所以要做判断
            if (index > -1) {
                disPlayName = cursor.getString(index);
            }
            cursor.close();
        }
        return disPlayName;
    }
}
